import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Tabs from '#tp/tabs/tabs'
import { Status,CaseType,CardType,Sex } from '@views/novel-coro-system/test-info/common/defaultData'
// ===================================================================== global declare
const { $fn, $Lazy, globalConfig } = window
const { COVIDUrl } = globalConfig
// ===================================================================== private component
const Page 			= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 		= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== data
const tabsData = [{ title:'小于4小时', status:'4'},{ title:'4-6小时', status:'6'},{ title:'6-12小时', status:'12'},{ title:'12-24小时', status:'24'},{ title:'24小时以上', status:'24+'}]
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms: [
			{ label: '状态',		name: 'status',			type:'select',		data:Status },
			{ label: '医院名称',		name: 'hosp_id',		type:'select',		loading:true,		idStr:'uuid',		nameStr:'hospName' },
			{ label: '条码号',		name: 'spec_code' },
			{ label: '病人姓名',		name: 'patient_name' },
			{ label: '录入时间',		names: ['create_at_start','create_at_end'], 	type:'date-range', 	loading:true,	name:'jz-time' },
			{ label: '证件号',		name: 'card_no' },
			{ label: '病人电话',		name: 'patient_phone' },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.index = $fn.local('xgxt-ybyj-index') || 0
		this.status = tabsData[this.index]['status']
		this.getSelect()
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 医院
			this.hostData = await f.getCache({ api:COVIDUrl+'Hospital/query',param:{page:1,page_num:10000,status:1} } )
			$fn.setRow( forms, 'hosp_id', this.hostData )
			this.setState({ forms })
			this.fetch()
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this, COVIDUrl+'caseinfo/query',{COVID:true,param:{ctime:this.status}} )
	
	// 表单
	cols = [
		{ title: '申请单条码', 		dataIndex: 'specCode', 			width:130 },
		{ title: '审核状态', 		dataIndex: 'status', 			...$fn.table.status,	render: text => $fn.getState(Status,text) },
		{ title: '受检人姓名', 		dataIndex: 'patientName', 		...$fn.table.name },
		{ title: '性别', 			dataIndex: 'sex', 				...$fn.table.sex, 		render: text => $fn.getState(Sex,text) },
		{ title: '年龄', 			dataIndex: 'age', 				...$fn.table.age },
		{ title: '受检人电话', 		dataIndex: 'patientPhone', 		...$fn.table.phone },
		{ title: '受检人类型', 		dataIndex: 'caseType', 			width:120,				render: text => $fn.getState(CaseType,text) },
		{ title: '采样时间', 		dataIndex: 'collTime',  			...$fn.table.time },
		{ title: '录入时间', 		dataIndex: 'createdAt',  			...$fn.table.time },
		{ title: '送检单位', 		dataIndex: 'hospId', 			width:180,	render: text => $fn.getState(this.hostData,text,'hospName','uuid') },
		{ title: '证件类型', 		dataIndex: 'cardType', 			...$fn.table.card_type,	render: text => $fn.getState(CardType,text) },
		{ title: '证件号', 			dataIndex: 'cardNo', 			...$fn.table.idcard },
		{ title: '送检科室', 		dataIndex: 'departmentName', 	width:180 },
		{ title: '送检医生', 		dataIndex: 'doctor', 			...$fn.table.name },
		{ title: '医生电话', 		dataIndex: 'doctorPhone', 		...$fn.table.phone },
	]
	
	render(){
		return (
			<>
				<Page title='样本预警' >
					<Tabs
						data={ tabsData } defaultActiveKey = { $fn.local('xgxt-ybyj-index') || 0 }
						onTabs = { ({ status },index) => {
							this.status = status
							this.setState({data:[]})
							this.searchFormRef.reset()
							$fn.local('xgxt-ybyj-index', index)
						}}
					/>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this) }
				</Page>
				
			</>
		)
	}
}

export default Index